package connection;


import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author Bruno
 */
public class ConnectionOracleOR {
    
	private String dbusername		=	"testes_or";
	private String dbuserpassword 	= 	"123456";
	private String dbhostip			=	"192.168.25.35";
	private String dbhostport 		= 	"1521";
	private String dbhostInstance 	= 	"xe";
	
	private Connection conexao 		= 	null;
    private Statement st			=	null;
    private PreparedStatement ps	=	null;
    
    public ConnectionOracleOR(){
    	
    }
    
	public ConnectionOracleOR( String dbusername, 
								String dbuserpassword,
								String dbhostip, 
								String dbhostport, 
								String dbhostInstance){
		
		this.dbusername 		= dbusername;
		this.dbuserpassword 	= dbuserpassword;
		this.dbhostip 			= dbhostip;
		this.dbhostport 		= dbhostport;
		this.dbhostInstance 	= dbhostInstance;
		
	}
	
	public Connection newConnection() throws Exception{//ClassNotFoundException {
        	     	    
		

		try{
    		 
    		 Class.forName("oracle.jdbc.driver.OracleDriver");
    		 //DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

        	 this.conexao = DriverManager.getConnection(
        			 	"jdbc:oracle:thin:@"+
        			 			this.dbhostip+":"+
        			 			this.dbhostport+":"+
        			 			this.dbhostInstance+"", 
        			 			this.dbusername, 
        			 			this.dbuserpassword);
        	 
        	 //this.st	=	this.conexao.createStatement();
        	 
    	 }catch (ClassNotFoundException e) {
		   
    		 throw new Exception("Ocorreu um erro ao tentar localizar o drive para banco de dados.");		    
    	 
    	 }catch (SQLException e) {
		    
    		 throw new Exception("Ocorreu um erro ao tentar conectar com o banco de dados.");
    	 
    	 }catch (Exception e){
                 
    		 throw new Exception("Ocorreu um erro desconhecido: "+e.getMessage());
 
    	 }
    	 
    	 
    	 return conexao;
    	 
	}

	
	public Statement getStatement(){
		 
        return this.st;

    }

    public PreparedStatement getPreparedStatement(){

        return this.ps;

    }
    
    
}
